import React from 'react'
import {Tabs,Select,Table, Divider, Tag,Modal,Button,message} from 'antd';
import './index.less';
import axios from 'axios';
import {PATH,IP} from '../../../../utils/urls';
import {createHashHistory} from 'history';
const { TabPane } = Tabs;
const { Option } = Select;
import BreadcrumbCustom from "../../../../components/BreadcrumbCustom";
export default class WarnSetupHardWare extends React.Component {
    columnsArray = [
        {
            title: 'id',
            dataIndex: 'id',
            key: 'id',
        },{
            title: 'AppId',
            dataIndex: 'appId',
            key: 'appId',
        },{
            title: '名称',
            dataIndex: 'resouceTypeName',
            key: 'resouceTypeName',
        },{
            title: 'IP地址',
            dataIndex: 'resouceIp',
            key: 'resouceIp',
        },{
            title: '操作',
            key: 'tags',
            dataIndex: 'tags',
            render: (tags,data) => (
                <span>
            {tags.map((tag,index) => {
                return (
                    <span key={index}><a href="javascript:void(0);" onClick={this.actionClick.bind(this,{tag},{index},{data})}>{tag}</a></span>
                );
            })}
          </span>
            ),
        },
    ];
    constructor(props) {
        super(props);
        this.state = {
            selectPosition: '添加设备',
            tabsPostion:"1",//tabs选中索引
            hardWareArray:[],//硬件资源
            softWareArray:[],//软件资源
            selectOrButtonShow:true//当为ture：显示设备下拉列表，false:显示添加软件按钮
        };
    }

    /**
     * 设备select的切换事件
     * @param tabPosition
     */
    changeSelectPosition = selectPosition => {
        this.setState({ selectPosition:selectPosition });
        console.log(selectPosition);
        let path = {
            pathname:"addequipmentresource"
        }

        this.props.history.push(path);
    };

    componentDidMount() {
        //获取设备列表
        this.getHardWareResource();
    }

    /**
     * 获取设备列表
     * @returns
     */
    getHardWareResource() {
        axios.post(PATH.hardwareResource, {})
            .then(response => {
                if (response.data.code == 0) {
                    let dataArray = response.data.data;
                    console.log(dataArray);
                    for(let i = 0;i<dataArray.length;i++){
                        dataArray[i].key = i;
                        dataArray[i].tags = ["告警设置"];
                    }
                    this.setState({
                        hardWareArray:dataArray
                    })
                }
            });
    }

    /**
     * 点击操作功能
     * @returns {*}
     */
    actionClick = (props0,props1,props2) => {
        console.log(props0);
        console.log(props1);
        console.log(props2);
        let path = {
            state:{
                appId:props2.data.id,
                name:props2.data.resouceName,
                resouceType:props2.data.resouceType
            },
        }
        console.log(path);
        localStorage.setItem("softIdCurrent",props2.data.id);
        //0服务器，1客户端，2UPS，3路由器，4交换机
        if(props2.data.resouceType == 0 || props2.data.resouceType == 1){
            path.pathname='/serviceclientwarnsetup';
        }else if(props2.data.resouceType == 2){
            path.pathname='/upswarnsetup';
        }else if(props2.data.resouceType == 3 ||props2.data.resouceType == 4){
            path.pathname='/networkwarnsetup';
        }
        this.props.history.push(path);
    }

    /**
     * 硬件切换到软件
     * @returns {*}
     */
    onHardToSoftFun=e=>{
        let path={
            pathname:'warnsetupsoftware'
        };
        this.props.history.push(path);
    }

    render() {
        return (
            <div>
                <BreadcrumbCustom first="日志" second="告警设置" />
                <div className="resourceAddType">
                    <div className="resourceManagerTitle">
                        <span className="equipmentSelect">设备资源管理</span>
                        <Divider type="vertical"/>
                        <span className="equipmentNoSelect" onClick={this.onHardToSoftFun}>软件资源管理</span>
                    </div>
                </div>
                <Table className= "reasureManagerClass" columns={this.columnsArray} dataSource={this.state.hardWareArray} bordered />
            </div>
        )
    }
}